package com.study;

import com.study.decorator.impl.CoconutDecorator;
import com.study.decorator.MilkyTea;
import com.study.decorator.PearlMilkyTea;
import com.study.decorator.impl.PuddingDecorator;
import com.study.design.DoubleCheckedSingleton;
import com.study.factory.Payment;
import com.study.factory.impl.PaymentFactory;
import com.study.handler.Leader;
import com.study.handler.LeaveRequest;
import com.study.handler.impl.Director;
import com.study.handler.impl.Manager;
import com.study.handler.impl.ViceGeneralManager;
import com.study.strategy.Context;
import com.study.strategy.impl.FristGun;
import com.study.template.BaseTemplate;
import com.study.template.TemplateMethod;
import com.study.template.TemplateMethod2;

public class Main {
    public static void main(String[] args) {
        //单例，双重锁校验
        DoubleCheckedSingleton instance = DoubleCheckedSingleton.getInstance();
        System.out.println(instance.test());
        System.out.println("===========单例模式===========");
        //工厂模式
        PaymentFactory paymentFactory = PaymentFactory.getInstance();
        Payment payment = paymentFactory.payment(2);
        System.out.println(payment.getPaymentName());
        payment.pay(100);
        System.out.println("===========工厂模式===========");
        Context context = new Context();
        context.setContext(new FristGun());
        context.daka();
        System.out.println("===========策略模式===========");
        MilkyTea milkyTea = new PearlMilkyTea();
        milkyTea = new CoconutDecorator(milkyTea);
        milkyTea = new PuddingDecorator(milkyTea);
        System.out.println(milkyTea.cost());
        System.out.println("===========装饰器模式===========");
        System.out.println("===========\r\n===========");
        System.out.println("===========构造责任链===========");
        //定义基础处理对象
        Leader objDirector,objManager,objGeneralManager;
        //实例化所有处理对象
        objDirector=new Director("老王");
        objManager=new Manager("赵强");
        objGeneralManager=new ViceGeneralManager("李波");
        // 建立职责链
        objDirector.setSuccessor(objManager); // 主任上级是经理
        objManager.setSuccessor(objGeneralManager); // 经理上级是副经理
        LeaveRequest lr1=new LeaveRequest("张三",15);
        //请求处理
        objDirector.handleRequest(lr1);
        System.out.println("===========责任链执行完毕===========");
        BaseTemplate tm = new TemplateMethod();
        tm.useTemplateMethod();

        System.out.println("");

        BaseTemplate tm2 = new TemplateMethod2();
        tm2.useTemplateMethod();
        System.out.println("===========模版方法执行完毕===========");
    }
}